﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <title>ccform正在加载请稍候...</title>
    <script type="text/javascript" src="../../Scripts/QueryString.js"></script>
    <script type="text/javascript" src="../../Scripts/config.js"></script>
    <script type="text/javascript" src="../Gener.js"></script>

	<link rel="stylesheet" type="text/css" href="../../Scripts/easyUI/themes/default/easyui.css" />
	<link rel="stylesheet" type="text/css" href="../../Scripts/easyUI/themes/icon.css" />
	<script type="text/javascript" src="../../Scripts/easyUI/jquery-1.8.0.min.js"></script>
	<script type="text/javascript" src="../../Scripts/easyUI/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../../Scripts/easyUI/locale/easyui-lang-zh_CN.js"></script>
	<script type="text/javascript" src="../../Scripts/EasyUIUtility.js"></script>
    
    <script src="../JS/Calendar/WdatePicker.js" type="text/javascript"></script>
    <link href="../JS/Calendar/skin/WdatePicker.css" rel="stylesheet" type="text/css" />

	<script type="text/javascript" src="../../Scripts/Cookie.js"></script>
	<script type="text/javascript" src="../../Scripts/QueryString.js"></script>

	<link href="../Style/CommStyle.css" rel="stylesheet" type="text/css" />

 
	<link href="En2018.css" rel="stylesheet" type="text/css" />
    <!-- 该文件可以被集成厂商自己定义风格,可以自己修改,以达到流程设计器与自己的系统风格统一. -->
    <link href="../../../DataUser/Style/ccbpm.css" rel="Stylesheet" />

    <!--UEditor-->
    <link href="../../Comm/umeditor1.2.3-utf8/themes/default/css/umeditor.css" type="text/css" rel="stylesheet" />
    <script type="text/javascript" src="../../Comm/umeditor1.2.3-utf8/third-party/template.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="../../Comm/umeditor1.2.3-utf8/umeditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="../../Comm/umeditor1.2.3-utf8/umeditor.min.js"></script>
    <script type="text/javascript" src="../../Comm/umeditor1.2.3-utf8/lang/zh-cn/zh-cn.js"></script>

    <!--杨玉慧 -->
    <script type="text/javascript">

        var frmData;
        var mapData;
        var mainData;
        var dtM; //方法集合.

        $(function () {

            var httpHandler = new HttpHandler("BP.WF.HttpHandler.WF_CommEntity");
            var enName = GetQueryString("EnName");
            var pkVal = GetPKVal();
            httpHandler.AddPara("EnName", enName);

            if (pkVal != null) {
                httpHandler.AddPara("PKVal", pkVal);
            }

            var data = httpHandler.DoMethodReturnString("Entity_Init");
            if (data.indexOf('err@') == 0) {
                $("#CCForm").html(data);
                return;
            }

            //解析json.
            frmData = JSON.parse(data);
            mapData = frmData["Sys_MapData"][0];
            mapData = new Entity("BP.Sys.MapData", mapData); //把他转化成entity.
            mainData = frmData["MainData"];
            dtM = frmData["dtM"];

            document.title = mapData.Name;

            InitToolbar(); //初始工具栏.

            RefMethod(); //初始化菜单.

            //生成傻瓜表单.
            GenerFoolFrm(mapData, mainData, frmData);


        })

        function RefMethod() {

            if (dtM.length == 0)
                return;

            //求出所有的分组名称.
            var groupName = "@基本信息";
            for (var i = 0; i < dtM.length; i++) {
                var en = dtM[i];
                if (en.GroupName == null)
                    continue;
                if (groupName.indexOf('@' + en.GroupName) == -1)
                    groupName += "@" + en.GroupName;
            }

            var gNames = groupName.split('@');

            //生成菜单.
            var html = "<div class='easyui-accordion' data-options='fit:true' id='accordion'>";
            html += "";
            for (var i = 0; i < gNames.length; i++) {
                var gName = gNames[i];
                if (gName == "")
                    continue;
                html += "<div title='" + gName + "' style='overflow:auto;'>";

                //填入菜单内容.
                html += "<ul class='navlist' >";
                for (var idx = 0; idx < dtM.length; idx++) {

                    var en = dtM[idx];
                    var myName = en.GroupName;
                    if (myName == null || myName == "")
                        myName = "基本信息";

                    if (gName != myName)
                        continue;

                    if (en.RefAttrKey != null || en.IsCanBatch == "1" || en.Visable == 0)
                        continue;

                    html += "<li>" + GenerRM(en) + "</li>";
                }
                html += "</ul>";   //end填入菜单内容.
                html += "</div>";
            }
            html += "</div>";

            $("#Left").append(html);
			$.parser.parse("#Left");
        }
        function OpenIt(url, title, w, h) {
            window.open(url);
            return;

           // var url = "./RefFunc/En2018.htm?EnName=" + mapBase.EnName + "&PKVal=" + pk;
            OpenBootStrapModal(url, "eudlgframe", this.document.title + ' : 详细', 1000, 550, "icon-edit", false, function () { }, null, function () {
                //location = location;
            });

           // window.open(url);
        }
        //设置按钮
        function InitToolbar() {
            var html = "";
            $("#Btn_New").hide();
            $("#Btn_Save").hide();
            $("#Btn_Delete").hide();

            //权限控制.
            if (mapData.GetPara("IsInsert") == 1) {
                $("#Btn_New").show();
               
            }
            if (mapData.GetPara("IsUpdate") == 1) {
                $("#Btn_Save").show();
            }
            if (mapData.GetPara("IsDelete") == 1) {
                var pkVal = GetPKVal();
                if (pkVal != null)
                    $("#Btn_Delete").show();
            }

           
        }

        function GenerFoolFrm(mapData, mainData, frmData) {

            frmData = frmData;
            var Sys_GroupFields = frmData.Sys_GroupField;
            var mapAtrrs = frmData.Sys_MapAttr;

            var tableWidth = 800; //  w - 40;
            var html = "<div class='easyui-tabs'>";
            for (var i = 0; i < Sys_GroupFields.length; i++) {
                var gf = Sys_GroupFields[i];
                var lab = gf.Lab;
                if (lab.indexOf(',') != -1) {
                    lab = lab.substring(0, lab.indexOf(','));
                }
                if (i == 0) {
                    html += "<div title='" + lab + "' id='" + gf.OID + "'>";
                } else {
                    html += "<div title='" + lab + "' data-options='closable:false' id='" + gf.OID + "'>";
                }
                html += InitMapAttr(frmData.Sys_MapAttr, mainData, gf.OID);
                html += "</div>";
            }
            html += "</div>";

            //加入隐藏控件.
            for (var i = 0; i < mapAtrrs.length; i++) {
                var attr = mapAtrrs[i];
                if (attr.UIVisible == 0) {
                    var defval = ConvertDefVal(attr);
                    html += "<input type='hidden' id='TB_" + attr.KeyOfEn + "' name='TB_" + attr.KeyOfEn + "' value='" + defval + "' />";
                }
            }

            $('#CCForm').html("").append(html);

            $.parser.parse("#CCForm");


            //   $.parser.parse("#CCForm");
            var isReadonly = GetQueryString("IsReadonly");

            //原有的。
            //为 DISABLED 的 TEXTAREA 加TITLE 
            var disabledTextAreas = $('#divCCForm textarea:disabled');
            $.each(disabledTextAreas, function (i, obj) {
                $(obj).attr('title', $(obj).val());
            })

            //根据NAME 设置ID的值
            var inputs = $('[name]');
            $.each(inputs, function (i, obj) {
                if ($(obj).attr("id") == undefined || $(obj).attr("id") == '') {
                    $(obj).attr("id", $(obj).attr("name"));
                }
            })

            //设置默认值
            for (var j = 0; j < frmData.Sys_MapAttr.length; j++) {

                var mapAttr = frmData.Sys_MapAttr[j];

                //添加 label
                //如果是整行的需要添加  style='clear:both'.
                var defValue = ConvertDefVal(mapAttr);

                if ($('#TB_' + mapAttr.KeyOfEn).length == 1) {
                    if (defValue == null || defValue == "null")
                        continue;
                    $('#TB_' + mapAttr.KeyOfEn).val(defValue);
                }

                if ($('#DDL_' + mapAttr.KeyOfEn).length == 1) {

                    // alert(mapAttr.KeyOfEn + " " + defValue);

                    // 判断下拉框是否有对应option, 若没有则追加
                    if ($("option[value='" + defValue + "']", '#DDL_' + mapAttr.KeyOfEn).length == 0) {

                        var mainTable = frmData.MainTable[0];
                        var selectText = mainTable[mapAttr.KeyOfEn + "Text"];

                        if (selectText == null || selectText == "")
                            selectText = defValue;

                        if (defValue == null || defValue == "") {

                        } else {
                            $('#DDL_' + mapAttr.KeyOfEn).append("<option value='" + defValue + "'>" + selectText + "</option>");
                        }
                    } else {
                        //设置选择的值
                        $('#DDL_' + mapAttr.KeyOfEn).val(defValue);
                    }
                }

                if ($('#CB_' + mapAttr.KeyOfEn).length == 1) {
                    if (defValue == "1")
                        $('#CB_' + mapAttr.KeyOfEn).attr("checked", true);
                    else
                        $('#CB_' + mapAttr.KeyOfEn).attr("checked", false);
                }

                if (mapAttr.UIIsEnable == "0") {
                    $('#TB_' + mapAttr.KeyOfEn).attr('disabled', true);
                    $('#DDL_' + mapAttr.KeyOfEn).attr('disabled', true);
                    $('#CB_' + mapAttr.KeyOfEn).attr('disabled', true);
                }
            }

        }

        //解析表单字段 MapAttr.
        function InitMapAttr(Sys_MapAttr, mainData, groupID) {

            var html = "<table border='0' style='width:97%;' >";
            var isDropTR = true;

            for (var i = 0; i < Sys_MapAttr.length; i++) {

                var attr = Sys_MapAttr[i];
                if (attr.GroupID != groupID || attr.UIVisible == 0 || attr.KeyOfEn == "MyNum")
                    continue;

                var enable = attr.UIIsEnable == "1" ? "" : " ui-state-disabled";

                var rm = null; //当前的方法.
                for (var iRm = 0; iRm < dtM.length; iRm++) {
                    if (dtM[iRm].RefAttrKey == attr.KeyOfEn) {
                        rm = dtM[iRm];
                    }
                }

                var name = null;
                if (attr.UIRefKeyText == "" || attr == null)
                    name = attr.Name;
                else
                    name = "<a href='" + attr.UIRefKeyText + "' target=_blank >" + attr.Name + "</a>";

                var lab = "";
                if (attr.UIContralType == 0)
                    lab = "<label for='TB_" + attr.KeyOfEn + "' class='" + (attr.UIIsInput == 1 ? "mustInput" : "") + "'>" + name + "</label>";

                if (attr.UIContralType == 1)
                    lab = "<label for='DDL_" + attr.KeyOfEn + "' class='" + (attr.UIIsInput == 1 ? "mustInput" : "") + "'>" + name + "</label>";

                if (attr.UIIsInput == 1 && attr.UIIsEnable == 1) {
                    lab += " <span style='color:red' class='mustInput' data-keyofen='" + attr.KeyOfEn + "' >*</span>";
                }

                //线性展示并且colspan=3
                if (attr.ColSpan == 3 || (attr.ColSpan == 4 && attr.UIHeight < 40)) {
                    isDropTR = true;
                    html += "<tr>";
                    html += "<td  class='FDesc' style='width:120px;'>" + lab + "</td>";
                    html += "<td colspan=3>";
                    html += InitMapAttrOfCtrl(attr);
                    html += "</td>";
                    html += "</tr>";

                    if (rm != null) {
                        html += "<tr>";
                        html += "<td class='FDesc' style='width:120px;'></td>";
                        html += "<td colspan=3>";
                        html += GenerRM(rm);
                        html += "</td>";
                        html += "</tr>";
                        isDropTR = true;
                    }
                    continue;
                }

                //线性展示并且colspan=4
                if (attr.ColSpan == 4) {
                    isDropTR = true;
                    html += "<tr>";
                    html += "<td colspan='4'>" + lab + "</br>";
                    html += InitMapAttrOfCtrl(attr);
                    html += "</td>";
                    html += "</tr>";

                    if (rm != null) {
                        html += "<tr>";
                        html += "<td class='FDesc' style='width:120px;'></td>";
                        html += "<td colspan=3>";
                        html += GenerRM(rm);
                        html += "</td>";
                        html += "</tr>";
                        isDropTR = true;
                    }
                    continue;
                }

                if (isDropTR == true) {
                    html += "<tr>";
                    html += "<td class='FDesc' style='width:120px;'>" + lab + "</td>";
                    html += "<td class='FContext'  >";
                    html += InitMapAttrOfCtrl(attr);
                    html += "</td>";
                    isDropTR = !isDropTR;

                    if (rm != null) {
                        html += "<td colspan=2>";
                        html += GenerRM(rm);
                        html += "</td>";
                        html += "</tr>";
                        isDropTR = true;
                    }
                    continue;
                }

                if (isDropTR == false) {

                    html += "<td class='FDesc' style='width:120px;'>" + lab + "</td>";
                    html += "<td class='FContext'>";
                    html += InitMapAttrOfCtrl(attr);
                    html += "</td>";
                    html += "</tr>";
                    isDropTR = !isDropTR;

                    if (rm != null) {
                        html += "<tr>";
                        html += "<td class='FDesc' style='width:120px;'></td>";
                        html += "<td colspan=3>";
                        html += GenerRM(rm);
                        html += "</td>";
                        html += "</tr>";
                        isDropTR = true;
                    }
                    continue;
                }
            }

            html += "</table>";
            return html;
        }

        function GenerRM(rm) {

            var icon = rm.Icon;
            if (rm.Icon == "" || rm.Icon == null) {
                icon = "../../Img/dot.png";
            }

            if (rm.Icon != null && rm.Icon.indexOf('http') != 0) {
                icon = "../" + rm.Icon;
            }
           
            // alert('没有实现@代国强, 需要根据窗口大小，弹出模态窗口..');
            //var html = "<img src='" + icon + "' border=0 style='width:16px;height:16px;' /><a href='javascript:OpenIt(\"" + rm.Url + "\",\"" + rm.Title + "\",\"" + rm.W + "\",\"" + rm.H + "\")'>" + rm.Title + "</a>";
            var html = "<a href='javascript:OpenUrlInRightFrame(this,\"" + rm.Url + "\")'><img src='" + icon + "' border=0 style='width:16px;height:16px;' />" + rm.Title + "</a>";
            //var html = "<a href=" + rm.url + "><img src='" + icon + "' border=0 style='width:16px;height:16px;' />" + rm.Title + "</a>";
            return html;
        }

        //在右侧框架中显示指定url的页面
        function OpenUrlInRightFrame(ele, url) {
            if (ele != null && ele != undefined) {
                //if (currShow == $(ele).text()) return;

                currShow = $(ele).parents('li').text(); //有回车符

                $.each($(ele).parents('ul').children('li'), function (i, e) {
                    $(e).children('div').css('font-weight', $(e).text() == currShow ? 'bold' : 'normal');
                });

                if (url.indexOf('?') == -1)
                    url += '?1=1';

                $('#rightFrame').empty();
                $('#rightFrame').append('<iframe scrolling="auto" frameborder="0"  src="' + url + '&s=' + Math.random() + '" style="width:100%;height:100%;"></iframe>');
            }
        }
        function InitMapAttrOfCtrl(mapAttr) {

            var str = '';
            var defValue = ""; //  ConvertDefVal(mapAttr);
            var isInOneRow = false; //是否占一整行
            var islabelIsInEle = false; //
            var eleHtml = '';

            //外部数据源类型.
            if (mapAttr.LGType == "0" && mapAttr.MyDataType == "1" && mapAttr.UIContralType == "1") {

                //枚举类型.
                if (mapAttr.UIIsEnable == 1)
                    enableAttr = "";
                else
                    enableAttr = "disabled='disabled'";

                return "<select name='DDL_" + mapAttr.KeyOfEn + "' " + (mapAttr.UIIsEnable == 1 ? '' : 'disabled="disabled"') + ">" + InitDDLOperation(frmData, mapAttr, defValue) + "</select>";
            }

            //外键类型.
            if (mapAttr.LGType == "2" && mapAttr.MyDataType == "1") {

                //枚举类型.
                if (mapAttr.UIIsEnable == 1)
                    enableAttr = "";
                else
                    enableAttr = "disabled='disabled'";

                return "<select name='DDL_" + mapAttr.KeyOfEn + "' " + (mapAttr.UIIsEnable == 1 ? '' : 'disabled="disabled"') + ">" + InitDDLOperation(frmData, mapAttr, defValue) + "</select>";
            }

            //外部数据类型.
            if (mapAttr.LGType == "0" && mapAttr.MyDataType == "1" && mapAttr.UIContral == 1) {

                //枚举类型.
                if (mapAttr.UIIsEnable == 1)
                    enableAttr = "";
                else
                    enableAttr = "disabled='disabled'";

                return "<select name='DDL_" + mapAttr.KeyOfEn + "' " + (mapAttr.UIIsEnable == 1 ? '' : 'disabled="disabled"') + ">" + InitDDLOperation(frmData, mapAttr, defValue) + "</select>";
            }

            //添加文本框 ，日期控件等
            //AppString
            if (mapAttr.MyDataType == "1" && mapAttr.UIContralType == 0) {  //不是外键

                if (mapAttr.UIHeight <= 40) //普通的文本框.
                {
                    var enableAttr = '';
                    if (mapAttr.UIIsEnable == 0)
                        enableAttr = "disabled='disabled'";

                    return "<input maxlength=" + mapAttr.MaxLen + "  name='TB_" + mapAttr.KeyOfEn + "' style='width:100%;height:23px;' type='text'  " + enableAttr + " />";
                }

                //普通的大块文本.
                return "<textarea maxlength=" + mapAttr.MaxLen + " style='height:" + mapAttr.UIHeight + "px;width:100%;' name='TB_" + mapAttr.KeyOfEn + "' type='text'  " + (mapAttr.UIIsEnable == 1 ? '' : ' disabled="disabled"') + " />"
            }

            //日期类型.
            if (mapAttr.MyDataType == 6) {
                var enableAttr = '';
                if (mapAttr.UIIsEnable == 1)
                    enableAttr = 'onfocus="WdatePicker({dateFmt:' + "'yyyy-MM-dd'})" + '";';
                else
                    enableAttr = "disabled='disabled'";

                return "<input " + enableAttr + " style='width:80px;' name='TB_" + mapAttr.KeyOfEn + "' type='text' />";
            }

            //时期时间类型.
            if (mapAttr.MyDataType == 7) {

                var enableAttr = '';
                if (mapAttr.UIIsEnable == 1)
                    enableAttr = 'onfocus="WdatePicker({dateFmt:' + "'yyyy-MM-dd HH:mm'})" + '";';
                else
                    enableAttr = "disabled='disabled'";

                return "<input  type='text'  style='width:120px;' " + enableAttr + " name='TB_" + mapAttr.KeyOfEn + "' />";
            }

            // boolen 类型.
            if (mapAttr.MyDataType == 4) {  // AppBoolean = 7

                if (mapAttr.UIIsEnable == 1)
                    enableAttr = "";
                else
                    enableAttr = "disabled='disabled'";

                //CHECKBOX 默认值
                var checkedStr = '';
                if (checkedStr != "true" && checkedStr != '1') {
                    checkedStr = ' checked="checked" ';
                }

                checkedStr = "";  

                return "<input " + enableAttr + " " + (defValue == 1 ? "checked='checked'" : "") + " type='checkbox' id='CB_" + mapAttr.KeyOfEn + "'  name='CB_" + mapAttr.KeyOfEn + "' " + checkedStr + " /><label for='CB_" + mapAttr.KeyOfEn + "' >" + mapAttr.Name + "</label>";
            }

            //枚举类型.
            if (mapAttr.MyDataType == 2 && mapAttr.LGType == 1) { //AppInt Enum
                if (mapAttr.UIIsEnable == 1)
                    enableAttr = "";
                else
                    enableAttr = "disabled='disabled'";

                return "<select name='DDL_" + mapAttr.KeyOfEn + "' " + (mapAttr.UIIsEnable == 1 ? '' : 'disabled="disabled"') + ">" + InitDDLOperation(frmData, mapAttr, defValue) + "</select>";
            }

            // AppDouble  AppFloat
            if (mapAttr.MyDataType == 5 || mapAttr.MyDataType == 3) {

                var enableAttr = '';
                if (mapAttr.UIIsEnable != 1)
                    enableAttr = "disabled='disabled'";

                // alert(mapAttr.KeyOfEn);
                return "<input style='text-align:right;width:80px;'  onkeyup=" + '"' + "if(isNaN(value)) execCommand('undo')" + '"' + " onafterpaste=" + '"' + "if(isNaN(value))execCommand('undo')" + '"' + " maxlength=" + mapAttr.MaxLen / 2 + "   type='text'" + enableAttr + " name='TB_" + mapAttr.KeyOfEn + "'/>";
            }

            if ((mapAttr.MyDataType == 2)) { //AppInt
                var enableAttr = '';
                if (mapAttr.UIIsEnable == 0 || mapAttr.KeyOfEn=="NodeID" ) {
                    enableAttr = "disabled='disabled'";
                }
                return "<input style='text-align:right;width:80px;' onkeyup=" + '"' + "if(isNaN(value) || (value%1 !== 0))execCommand('undo')" + '"' + " onafterpaste=" + '"' + "if(isNaN(value) || (value%1 !== 0))execCommand('undo')" + '"' + " maxlength=" + mapAttr.MaxLen / 2 + "   type='text'" + enableAttr + " name='TB_" + mapAttr.KeyOfEn + "'/>";
            }

            //AppMoney  AppRate
            if (mapAttr.MyDataType == 8) {
                var enableAttr = '';
                if (mapAttr.UIIsEnable == 1) {

                } else {
                    enableAttr = "disabled='disabled'";
                }
                return "<input style='text-align:right;width:80px;' onkeyup=" + '"' + "if(isNaN(value))execCommand('undo')" + '"' + " onafterpaste=" + '"' + "if(isNaN(value))execCommand('undo')" + '"' + " maxlength=" + mapAttr.MaxLen / 2 + "   type='text'" + enableAttr + " name='TB_" + mapAttr.KeyOfEn + "'/>";
            }

            alert(mapAttr.Name + "的类型没有判断.");
            return;
        }

        //填充默认数据
        function ConvertDefVal(attr) {

            //通过MAINTABLE返回的参数
            for (var ele in frmData.MainTable[0]) {
                if (attr.KeyOfEn == ele && frmData.MainTable[0] != '') {
                    result = frmData.MainTable[0][ele];
                    break;
                }
            }

            if (result != undefined && typeof (result) == 'string') {
                //result = result.replace(/｛/g, "{").replace(/｝/g, "}").replace(/：/g, ":").replace(/，/g, ",").replace(/【/g, "[").replace(/】/g, "]").replace(/；/g, ";").replace(/~/g, "'").replace(/‘/g, "'").replace(/‘/g, "'");
            }
            return result = unescape(result);
        }

        //初始化下拉列表框的OPERATION
        function InitDDLOperation(flowData, mapAttr, defVal) {

            var operations = '';

            var data = frmData[mapAttr.KeyOfEn];
            if (data == undefined)
                data = frmData[mapAttr.UIBindKey];

            //外键类型.
            if (mapAttr.LGType == 2) {

                var data = frmData[mapAttr.KeyOfEn];
                if (data == undefined)
                    data = frmData[mapAttr.UIBindKey];

                if (data == undefined) {
                    alert('没有获得约定的数据源..' + mapAttr.KeyOfEn + " " + mapAttr.UIBindKey);
                    return;
                }
                
              //  alert(defVal);


                $.each(data, function (i, obj) {
                    operations += "<option " + (obj.No == defVal ? " selected='selected' " : "") + " value='" + obj.No + "'>" + obj.Name + "</option>";
                });
            }

            if (mapAttr.LGType == 0 && data != undefined) {
                $.each(data, function (i, obj) {
                    operations += "<option " + (obj.No == defVal ? " selected='selected' " : "") + " value='" + obj.No + "'>" + obj.Name + "</option>";
                });
                return operations;
            }


            //枚举类型.
            if (mapAttr.LGType == 1) {

                var enums = frmData.Sys_Enum;
                enums = $.grep(enums, function (value) {
                    return value.EnumKey == mapAttr.UIBindKey;
                });

                $.each(enums, function (i, obj) {
                    operations += "<option " + (obj.IntKey == defVal ? " selected='selected' " : "") + " value='" + obj.IntKey + "'>" + obj.Lab + "</option>";
                });
            }


            //外部数据源类型 MyFlowGener.js.InitDDLOperation
            if (mapAttr.LGType == 0) {
                var fn;
                try {
                    if (mapAttr.UIBindKey) {
                        fn = eval(mapAttr.UIBindKey);
                    }
                } catch (e) {
                }
                if (typeof fn == "function") {
                    $.each(fn.call(), function (i, obj) {
                        operations += "<option " + (obj.No == defVal ? " selected='selected' " : "") + " value='" + obj.No + "'>" + obj.Name + "</option>";
                    });
                } else if (typeof CommonHandler == "function") {
                    CommonHandler.call("", mapAttr.UIBindKey, function (data) {
                        GenerBindDDL("DDL_" + mapAttr.KeyOfEn, data, "No", "Name");
                    })
                } else {
                    alert('没有获得约定的数据源..' + mapAttr.KeyOfEn + " " + mapAttr.UIBindKey);
                    //alert('没有获得约定的数据源.');
                }
            }
            return operations;
        }

        //新建.
        function New() {
            var enName = GetQueryString("EnName");
            var url = "?EnName=" + GetQueryString("EnName") + "&RefKey=" + GetQueryString("RefKey") + "&RefVal=" + GetQueryString("RefVal") + "&t=" + Math.random();
            window.location.href = url; //刷新.
        }

        function Save() {
            this.Update();
        }

        //更新.
        function Update() {

            var enName = GetQueryString("EnName");
            var en = new Entity(enName);
            var pkval = GetPKVal();

            if (pkval == null || pkval == "") {

                en.CopyForm();

                if (en.Insert() == 0)
                    return;

                var pkval = en.GetPKVal();


                var url = "?EnName=" + GetQueryString("EnName") + "&PKVal=" + pkval + "&RefKey=" + GetQueryString("RefKey") + "&RefVal=" + GetQueryString("RefVal");
                window.location.href = url; //刷新.
                return;
            }

            en.pkval = pkval;
            en.RetrieveFromDBSources();

            en.CopyForm();
            en.pkval = pkval;

            var info = en.Update();
            if (info != 1) {
                alert('更新错误:' + info);
            }

            var url = "?EnName=" + GetQueryString("EnName") + "&PKVal=" + en.pkval + "&RefKey=" + GetQueryString("RefKey") + "&RefVal=" + GetQueryString("RefVal");
            window.location.href = url; //刷新.
        }

        function Delete() {

            if (window.confirm('您确定要删除吗？') == false)
                return;

            var enName = GetQueryString("EnName");
            var en = new Entity(enName);
            en.pkval = GetPKVal();
            en.RetrieveFromDBSources();
            en.Delete();

            $("#Btns").html("");
            $("#Left").html("");
            $("#CCForm").html("删除成功..");

            alert("删除成功.");
            window.close();
            CloseIt();
        }

        function CloseIt() {
            if (window.parent && window.parent.CloseBootstrapDialog) {
                window.parent.CloseBootstrapDialog("取消");
            } else {
                window.close();
            }
        }

        $(function () {
            var Accordion = function (el, multiple) {
                this.el = el || {};
                this.multiple = multiple || false;

                // Variables privadas
                var links = this.el.find('.link');
                // Evento
                links.on('click', { el: this.el, multiple: this.multiple }, this.dropdown)
            }

            Accordion.prototype.dropdown = function (e) {
                var $el = e.data.el;
                $this = $(this),
			$next = $this.next();

                $next.slideToggle();
                $this.parent().toggleClass('open');

                if (!e.data.multiple) {
                    $el.find('.submenu').not($next).slideUp().parent().removeClass('open');
                };
            }

            var accordion = new Accordion($('#accordion'), false);
           
        });
    </script>
</head> 
<body class="easyui-layout">
	
	<div class="easyui-layout" data-options="region:'center'" border="false">

		<div id="Left" data-options="region:'west'" style="width:195px" ></div>
       
    	<div id="rightFrame" data-options="region:'center',noheader:true">
            <div class="easyui-layout" data-options="fit:true">
                <div id="Btns" data-options="region:'north',noheader:true,split:false,border:false" style="height: 30px;padding: 2px; background-color: #E0ECFF">
                    <a id="Btn_New" href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-new'" onclick="New()">新建</a>
                    <a id="Btn_Save" href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-save'" onclick="Update()">保存</a>
                    <a id="Btn_Delete" href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-delete'" onclick="Delete()">删除</a>
                    <a id="Btn_Close" href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-no'" onclick="CloseIt()">关闭</a>
                </div>
                <div data-options="region:'center',noheader:true,border:false" style="margin:0px">
                    <div id="CCForm" data-options="region:'center',noheader:true,border:false" style="margin:0px;padding:0px">
             
			            <br />
			            <img src='./../../Img/loading.gif' />正在初始化表单模板及数据，请耐心等待。。。
			            <br />
                    </div>
                </div>
            </div>
	    </div>
	</div>
</body>
</html>
